/*   1:    */ package org.jetbrains.jps.model.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.text.XmlCharsetDetector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.JpsEncodingConfigurationService;
import org.jetbrains.jps.model.JpsEncodingProjectConfiguration;
import org.jetbrains.jps.model.JpsModel;
import org.jetbrains.jps.model.ex.JpsElementBase;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.util.JpsPathUtil;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */ 
/*  24:    */ public class JpsEncodingProjectConfigurationImpl
/*  25:    */   extends JpsElementBase<JpsEncodingProjectConfigurationImpl>
/*  26:    */   implements JpsEncodingProjectConfiguration
/*  27:    */ {
/*  28: 45 */   private static final Logger a = Logger.getInstance(JpsEncodingProjectConfigurationImpl.class);
/*  29: 46 */   public static final JpsElementChildRole<JpsEncodingProjectConfiguration> ROLE = JpsElementChildRoleBase.create("encoding configuration");
/*  30:    */   private static final String b = ".xml";
/*  31: 48 */   private final Map<String, String> c = new HashMap();
/*  32:    */   private final String d;
/*  33:    */   
/*  34:    */   public JpsEncodingProjectConfigurationImpl(Map<String, String> paramMap, String paramString)
/*  35:    */   {
/*  36: 52 */     this.c.putAll(paramMap);
/*  37: 53 */     this.d = paramString;
/*  38:    */   }
/*  39:    */   
/*  40:    */   @Nullable
/*  41:    */   public String getEncoding(@NotNull File paramFile)
/*  42:    */   {
/*  43: 59 */     if (paramFile == null) {
/*  44: 59 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsEncodingProjectConfigurationImpl", "getEncoding" }));
/*  45:    */     }
/*  46: 59 */     if (a(paramFile)) {
/*  47:    */       try
/*  48:    */       {
/*  49: 61 */         String str1 = XmlCharsetDetector.extractXmlEncodingFromProlog(FileUtil.loadFileBytes(paramFile));
/*  50: 62 */         if (str1 != null) {
/*  51: 63 */           return str1;
/*  52:    */         }
/*  53:    */       }
/*  54:    */       catch (IOException localIOException)
/*  55:    */       {
/*  56: 67 */         a.info("Cannot detect encoding for xml file " + paramFile.getAbsolutePath(), localIOException);
/*  57:    */       }
/*  58:    */     }
/*  59: 71 */     if (!this.c.isEmpty())
/*  60:    */     {
/*  61: 73 */       localObject = paramFile;
/*  62: 74 */       while (localObject != null)
/*  63:    */       {
/*  64: 75 */         String str2 = (String)this.c.get(JpsPathUtil.pathToUrl(FileUtilRt.toSystemIndependentName(((File)localObject).getPath())));
/*  65: 77 */         if (str2 != null) {
/*  66: 78 */           return str2;
/*  67:    */         }
/*  68: 81 */         localObject = FileUtilRt.getParentFile((File)localObject);
/*  69:    */       }
/*  70:    */     }
/*  71: 85 */     if (this.d != null) {
/*  72: 86 */       return this.d;
/*  73:    */     }
/*  74: 89 */     Object localObject = getModel();
/*  75: 90 */     assert (localObject != null);
/*  76: 91 */     return JpsEncodingConfigurationService.getInstance().getGlobalEncoding(((JpsModel)localObject).getGlobal());
/*  77:    */   }
/*  78:    */   
/*  79:    */   private static boolean a(File paramFile)
/*  80:    */   {
/*  81: 95 */     String str = paramFile.getName();
/*  82: 96 */     return SystemInfo.isFileSystemCaseSensitive ? str.endsWith(".xml") : StringUtil.endsWithIgnoreCase(str, ".xml");
/*  83:    */   }
/*  84:    */   
/*  85:    */   @NotNull
/*  86:    */   public Map<String, String> getUrlToEncoding()
/*  87:    */   {
/*  88:102 */     Map tmp7_4 = Collections.unmodifiableMap(this.c);
/*  89:102 */     if (tmp7_4 == null) {
/*  90:102 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/impl/JpsEncodingProjectConfigurationImpl", "getUrlToEncoding" }));
/*  91:    */     }
/*  92:102 */     return tmp7_4;
/*  93:    */   }
/*  94:    */   
/*  95:    */   @Nullable
/*  96:    */   public String getProjectEncoding()
/*  97:    */   {
/*  98:108 */     return this.d;
/*  99:    */   }
/* 100:    */   
/* 101:    */   @NotNull
/* 102:    */   public JpsEncodingProjectConfigurationImpl createCopy()
/* 103:    */   {
/* 104:114 */     void tmp15_12 = new JpsEncodingProjectConfigurationImpl(this.c, this.d);
/* 105:114 */     if (tmp15_12 == null) {
/* 106:114 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/impl/JpsEncodingProjectConfigurationImpl", "createCopy" }));
/* 107:    */     }
/* 108:114 */     return tmp15_12;
/* 109:    */   }
/* 110:    */   
/* 111:    */   public void applyChanges(@NotNull JpsEncodingProjectConfigurationImpl paramJpsEncodingProjectConfigurationImpl)
/* 112:    */   {
/* 113:119 */     if (paramJpsEncodingProjectConfigurationImpl == null) {
/* 114:119 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsEncodingProjectConfigurationImpl", "applyChanges" }));
/* 115:    */     }
/* 116:    */   }
/* 117:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.impl.JpsEncodingProjectConfigurationImpl

 * JD-Core Version:    0.7.0.1

 */